package com.example.facecompare.common.tool.thread;

import java.util.List;

public class ListTraversalTask implements Runnable {
    private final List<String> collection;

    public ListTraversalTask(List<String> collection) {
        this.collection = collection;
    }

    @Override
    public void run() {
        // 使用同步块确保多线程同时访问集合时不会重复遍历
        synchronized (collection) {
            for (String value : collection) {
                System.out.println(Thread.currentThread().getName() + " 遍历到了值: " + value);
            }
        }
    }
}
